package com.sgb.kjwl.view.ui.fragment.transport;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.fondesa.recyclerviewdivider.DividerDecoration;
import com.google.android.material.tabs.TabLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;
import com.sgb.kjwl.AppLazyFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentCarsBinding;
import com.sgb.kjwl.model.entity.ProListEntity;
import com.sgb.kjwl.model.entity.transport.CarHallEntity;
import com.sgb.kjwl.model.entity.transport.FilterTabEntity;
import com.sgb.kjwl.model.entity.transport.GoodsInfoTypeEntity3;
import com.sgb.kjwl.model.entity.transport.GoodsSourceLocationEntity;
import com.sgb.kjwl.model.entity.transport.SingleItemConstant;
import com.sgb.kjwl.utils.DefaultUtil;
import com.sgb.kjwl.utils.NumberUtil;
import com.sgb.kjwl.utils.VehicleConstant;
import com.sgb.kjwl.view.constant.RouterKey;
import com.sgb.kjwl.view.event.LogisticsEvent;
import com.sgb.kjwl.view.ui.activity.MainActivity;
import com.sgb.knowledgeshare.view.activity.PlayListActivity;
import com.sgb.kjwl.view.ui.activity.vehicleManagement.VehicleDetailActivity;
import com.sgb.kjwl.view.ui.adapter.home.CarsHallAdapter;
import com.sgb.kjwl.view.ui.adapter.transport.LogisticsFilterTabAdapter;
import com.sgb.kjwl.view.widget.GoodsTypePopWindow3;
import com.sgb.kjwl.view.widget.LoadingTimePopWindow;
import com.sgb.kjwl.view.widget.ThreeLevelAreaWindow;
import com.sgb.kjwl.viewmodel.transport.CarsModel;
import com.sgb.member.MemberConfig;
import com.sgb.member.entity.QualityMemberBean;
import com.sgb.member.ui.activity.ComApplyOrInvitePersonActivity;
import com.sgb.member.ui.activity.ComApplyOrInvitePersonShenPiActivity;
import com.sgb.member.weight.MemberCommonDialog;
import com.swgk.core.base.di.AppComponent;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.event.EventConstant;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PermissionUtils;
import com.swgk.core.util.SharedPreferenceUtil;
import com.swgk.core.util.UiUtil;
import com.swgk.core.util.UserOperating;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;


/**
 * @author: 杨畔
 * @date: 3/1/21 9:16 AM
 * @Description: 车辆大厅/货车信息
 */
public class CarsFragment extends AppLazyFragment implements TabLayout.OnTabSelectedListener {
    CarsModel viewModel;
    FragmentCarsBinding binding;
    //
    private Activity _mActivity;
    //筛选栏
    private final int TAB_CAR_LOCATION = 0;
    private final int TAB_CAR_LENGTH = 1;
    private final int TAB_CAR_FEATURE = 2;
    private final int TAB_CAR_DATE = 3;
    private List<FilterTabEntity> mFilterList;
    private LogisticsFilterTabAdapter mFilterAdapter;
    //页面弹窗
    private GoodsTypePopWindow3 mTypePop;//车型
    private ThreeLevelAreaWindow mSendPop;//车辆发货地
    private GoodsTypePopWindow3 mLenPop;//车长
    private GoodsTypePopWindow3 mFeaturePop;//功能
    private LoadingTimePopWindow mLoadingTimePop;//装车时间
    //列表数据
    private int mPage = 1;
    private List<CarHallEntity> mList;
    private CarsHallAdapter mAdapter;
    //是否是车辆大厅
    private boolean mIsCarHall = true;
    private String websiteNo;//主页身份no
    private String websiteType;//主页身份(个人、企业、团队)

    public static CarsFragment newInstance() {
        return newInstance(true);
    }

    public static CarsFragment newInstance(boolean isCarHall) {
        CarsFragment fragment = new CarsFragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean(RouterKey.BOOLEAN, isCarHall);
        fragment.setArguments(bundle);
        return fragment;
    }

    /**
     * 前台主页--物流经营--自营车辆
     *
     * @param
     * @return
     */
    public static CarsFragment newInstance(String websiteType, String no) {
        CarsFragment fragment = new CarsFragment();
        Bundle bundle = new Bundle();
        bundle.putBoolean(RouterKey.BOOLEAN, true);
        bundle.putString("websiteType", websiteType);
        bundle.putString("no", no);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        _mActivity = (Activity) context;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_cars, container, false);
        binding.setLifecycleOwner(this);
        viewModel = new ViewModelProvider(this).get(CarsModel.class);
        return binding.getRoot();
    }

    @Override
    protected void onLazyLoad() {
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
        //获取是否是车辆大厅的参数
        if (getArguments() != null) {
            mIsCarHall = getArguments().getBoolean(RouterKey.BOOLEAN, true);
            viewModel.setIsCarHall(mIsCarHall);
            websiteNo = getArguments().getString("no");
            viewModel.websiteNo = getArguments().getString("no");
            websiteType = getArguments().getString("websiteType");
            viewModel.websiteType = getArguments().getString("websiteType");
        }
        initRecycler();
        initPopup();
        initEvent();
        initData();
    }

    private void initRecycler() {
        //筛选栏
        mFilterList = new ArrayList<>();
        viewModel.initFilterTab(mFilterList);
        mFilterAdapter = new LogisticsFilterTabAdapter(mFilterList);
        binding.rvFindCarByMapFilter.setNestedScrollingEnabled(false);
        binding.rvFindCarByMapFilter.setLayoutManager(new LinearLayoutManager(_mActivity, RecyclerView.HORIZONTAL, false));
        DividerDecoration.builder(_mActivity)
                .color(Color.TRANSPARENT)
                .size(10, TypedValue.COMPLEX_UNIT_DIP)
                .build()
                .addTo(binding.rvFindCarByMapFilter);
        mFilterAdapter.bindToRecyclerView(binding.rvFindCarByMapFilter);
        //车辆列表
        mList = new ArrayList<>();
        if (!TextUtils.isEmpty(websiteType)) {
            mAdapter = new CarsHallAdapter(mList, true);
        } else {
            mAdapter = new CarsHallAdapter(mList);
        }
        binding.carsList.setLayoutManager(new LinearLayoutManager(_mActivity));
//        binding.carsList.addItemDecoration(new RecyclerCustomDecoration(0, 0, 0,
//                _mActivity.getResources().getDimension(R.dimen.dp5),
//                Color.TRANSPARENT));
        mAdapter.bindToRecyclerView(binding.carsList);
    }

    private void initPopup() {
        mFilterAdapter.setTabStatus(TAB_CAR_LOCATION, LogisticsFilterTabAdapter.SELECTED);
        //发货地
        mSendPop = new ThreeLevelAreaWindow(_mActivity) {
            @Override
            protected void resultContent(String name, String simpleName) {
                mFilterAdapter.setTabTitle(TAB_CAR_LOCATION, DefaultUtil.getMaxLengthText(simpleName, 4));
            }
        };
        mSendPop.setAreaSingle();
        mSendPop.setCitySingle();
        mSendPop.setProvinceSingle();
        mSendPop.setShowSimpleName(true);
        mSendPop.setAllSingleSelect(true);
        mSendPop.setOnlyShowProAndCity(true);
        mSendPop.setOnResultClick(new ThreeLevelAreaWindow.OnResultClickProxy() {
            @Override
            protected void result(GoodsSourceLocationEntity entity) {
                viewModel.ldFilter.getValue().setSend(entity);
                //刷新数据
                refreshList();
            }
        });
        mSendPop.setOnDismissListener(() -> {
            mFilterAdapter.setTabStatus(TAB_CAR_LOCATION, LogisticsFilterTabAdapter.SELECTED);
        });
        //车长
        mLenPop = new GoodsTypePopWindow3(_mActivity);
        mLenPop.setOnResultClick((key1, key2, key3) -> {
            GoodsInfoTypeEntity3 entity = (GoodsInfoTypeEntity3) key1;
            mFilterAdapter.setTabTitle(TAB_CAR_LENGTH, entity.getName());
            viewModel.ldFilter.getValue().setCarLen(entity);
            //刷新
            refreshList();
        });
        mLenPop.setOnDismissListener(() -> {
            if ("车长".equals(mFilterList.get(TAB_CAR_LENGTH).getTitle())) {
                mFilterAdapter.setTabStatus(TAB_CAR_LENGTH, LogisticsFilterTabAdapter.NORMAL);
            } else {
                mFilterAdapter.setTabStatus(TAB_CAR_LENGTH, LogisticsFilterTabAdapter.SELECTED);
            }
        });
        //车辆类型
        mTypePop = new GoodsTypePopWindow3(_mActivity);
        mTypePop.setOnResultClick((key1, key2, key3) -> {
            GoodsInfoTypeEntity3 entity = (GoodsInfoTypeEntity3) key1;
            viewModel.ldFilter.getValue().setCarType(entity);
            binding.tlFindCarByMap.selectTab(binding.tlFindCarByMap.getTabAt((Integer) key2));
            //根据车型筛选数据
            filterByCarType();
        });
        mTypePop.setOnDismissListener(() -> {
            binding.ivFindCarByMapEdit.setImageResource(R.mipmap.icon_tab_unfold);
        });
        //功能
        mFeaturePop = new GoodsTypePopWindow3(_mActivity);
        mFeaturePop.setOnResultClick((key1, key2, key3) -> {
            GoodsInfoTypeEntity3 entity = (GoodsInfoTypeEntity3) key1;
            mFilterAdapter.setTabTitle(TAB_CAR_FEATURE, entity.getName());
            viewModel.ldFilter.getValue().setCarFunction(entity);
            //刷新
            refreshList();
        });
        mFeaturePop.setOnDismissListener(() -> {
            if ("功能".equals(mFilterList.get(TAB_CAR_FEATURE).getTitle())) {
                mFilterAdapter.setTabStatus(TAB_CAR_FEATURE, LogisticsFilterTabAdapter.NORMAL);
            } else {
                mFilterAdapter.setTabStatus(TAB_CAR_FEATURE, LogisticsFilterTabAdapter.SELECTED);
            }
        });
        //装车时间
        mLoadingTimePop = new LoadingTimePopWindow(_mActivity);
        mLoadingTimePop.setOnResultClick((key1, key2, key3) -> {
            long startTime = (long) key1;
            long endTime = (long) key2;
            viewModel.ldFilter.getValue().setShipmentTime(startTime);
            viewModel.ldFilter.getValue().setShipmentEndTime(endTime);
            if (startTime != 0 && endTime != 0) {//要求回显
                mFilterAdapter.setTabTitle(TAB_CAR_DATE, UiUtil.get2Time(startTime) + "-" + UiUtil.get2Time(endTime));
            } else if (startTime != 0) {
                mFilterAdapter.setTabTitle(TAB_CAR_DATE, UiUtil.get2Time(startTime));
            } else if (endTime != 0) {
                mFilterAdapter.setTabTitle(TAB_CAR_DATE, UiUtil.get2Time(endTime));
            } else {
                mFilterAdapter.setTabTitle(TAB_CAR_DATE, "装车时间");
            }
            //刷新
            refreshList();
        });
        mLoadingTimePop.setOnDismissListener(() -> {
            if (viewModel.ldFilter.getValue().getShipmentTime() != 0
                    || viewModel.ldFilter.getValue().getShipmentEndTime() != 0) {
                mFilterAdapter.setTabStatus(TAB_CAR_DATE, LogisticsFilterTabAdapter.SELECTED);
            } else {
                mFilterAdapter.setTabStatus(TAB_CAR_DATE, LogisticsFilterTabAdapter.NORMAL);
            }
        });
    }
   private QualityMemberBean bean1;
    private void initEvent() {
        binding.setOnClick(this);
        //前台主页--物流经营展示自营车辆-->没有该筛选栏
        if (!TextUtils.isEmpty(websiteType)) {
            binding.rvFindCarByMapFilter.setVisibility(View.GONE);
        } else {
            binding.rvFindCarByMapFilter.setVisibility(View.VISIBLE);
        }
        binding.srlFindCarByMap.setEnableRefresh(mIsCarHall);
        binding.srlFindCarByMap.setOnRefreshLoadMoreListener(new OnRefreshLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                viewModel.getCarToList(getActivity(), mPage);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                mPage = 1;
                viewModel.getCarToList(getActivity(), mPage);
            }
        });
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            CarHallEntity entity = mList.get(position);
            if (entity.getItemType() == SingleItemConstant.TYPE_ONE) {
                //跳转车辆详情
                VehicleDetailActivity.startNew(_mActivity, entity.getDriverAuthNo());
            } else {
                //视频播放
                Intent intent = new Intent(getActivity(), PlayListActivity.class);
                intent.putExtra(PlayListActivity.VIDEOLISTBEAN, (Serializable) entity.getVideoList());
                intent.putExtra(PlayListActivity.PSO, 0);
                intent.putExtra(PlayListActivity.VIDEOTYPE, "home_bigVideo");
                startActivity(intent);
            }

        });
        //点击邀请回调
        mAdapter.setPermissionsInterface(entity -> {
            if (UserOperating.getInstance().isNotLogged(getActivity())) {
                return;
            }
            if (!MemberConfig.getInstance().isHavePermission("14_shenqingjiameng1")) {
                MToast.showToast(getActivity(), "没有权限操作，请找企业管理员分配权限");
                return;
            }
            bean1 = new QualityMemberBean();
            bean1.setCompanyNo(entity.getCompanyNo());
            bean1.setCompanyName(entity.getName());
            bean1.setNo(entity.getUserNo());

            if (MemberConfig.getInstance().getComType() == MemberConfig.WEBSITE_FOR_COMPANY) {
                String companyNo = SharedPreferenceUtil.getInstance().getSaveStringData(SharedPreferenceUtil.COMPANY_NO, "");
                viewModel.getProcessStatus(companyNo, "inviteJoinCompany");
            } else {
                MToast.showToast(getActivity(), "个人/团队网站暂不支持该操作");
            }
        });
        //显示隐藏回到顶部按钮
        binding.carsList.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                //判断是否滑动结束
                if (newState != RecyclerView.SCROLL_STATE_IDLE) return;
                //判断当前地步位置
                RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
                if (layoutManager instanceof LinearLayoutManager) {
                    LinearLayoutManager linearManager = (LinearLayoutManager) layoutManager;
                    //获取最后一个可见view的位置
                    int lastItemPosition = linearManager.findLastVisibleItemPosition();
                    //显示隐藏回到顶部按钮
                    binding.ivFindCarByMapBackTop.setVisibility(lastItemPosition > 10 ? View.VISIBLE : View.GONE);
                }
            }
        });
        //筛选点击
        mFilterAdapter.setOnItemClickListener((adapter, view, position) -> {
            switch (position) {
                case TAB_CAR_LOCATION://车辆位置
                    if (viewModel.ldAddress.getValue() != null) {
                        mFilterAdapter.setTabStatus(TAB_CAR_LOCATION, LogisticsFilterTabAdapter.EXPAND);
                        showPopup(mSendPop);
                    }
                    break;
                case TAB_CAR_LENGTH://车长
                    if (viewModel.ldCarLen.getValue() != null) {
                        mFilterAdapter.setTabStatus(TAB_CAR_LENGTH, LogisticsFilterTabAdapter.EXPAND);
                        showPopup(mLenPop);
                    }
                    break;
                case TAB_CAR_FEATURE://功能
                    if (viewModel.ldCarFunction.getValue() != null) {
                        mFilterAdapter.setTabStatus(TAB_CAR_FEATURE, LogisticsFilterTabAdapter.EXPAND);
                        showPopup(mFeaturePop);
                    }
                    break;
                case TAB_CAR_DATE://装车时间
                    mFilterAdapter.setTabStatus(TAB_CAR_DATE, LogisticsFilterTabAdapter.EXPAND);
                    showPopup(mLoadingTimePop);
                    break;
            }
        });
        //车辆类型选中监听
        binding.tlFindCarByMap.addOnTabSelectedListener(this);
        //车辆类型数据
        viewModel.ldCarType.observe(this, list -> {
            mTypePop.setData(list, 0);
            //添加tab
            binding.tlFindCarByMap.removeAllTabs();
            for (GoodsInfoTypeEntity3 entity3 : list) {
                binding.tlFindCarByMap.addTab(binding.tlFindCarByMap.newTab().setText(entity3.getName()));
            }
        });
        //车辆长度数据
        viewModel.ldCarLen.observe(this, list -> {
            mLenPop.setData(VehicleConstant.sortCarLength(list), 0);
        });
        //省市区监听
        viewModel.ldAddress.observe(this, addressEntities -> {
            //设置数据
            mSendPop.setDataAndPosition(addressEntities, "", "", "",
                    true, true);
        });
        //todo 暂时没用（开局根据定位查找省市区时使用），查找地区下标监听
        viewModel.ldPosition.observe(this, positionEntity -> {
            GoodsSourceLocationEntity entity = viewModel.ldFilter.getValue().getSend();
            mSendPop.setDataAndPosition(viewModel.ldAddress.getValue(), entity.getProvinceName(),
                    "", "", true, true);
            //设置车辆位置
            mFilterAdapter.setTabTitle(TAB_CAR_LOCATION, DefaultUtil.getMaxLengthText(entity.getProvinceName(), 4));
        });
        //地图找车数据
        viewModel.ldCars.observe(this, this::syncData);
        //车辆功能数据
        viewModel.ldCarFunction.observe(this, list -> mFeaturePop.setData(list, 0));
        viewModel.statusLiveData.observe(this, status -> {
            if (status.equals("1")) {
                MemberCommonDialog dialog = new MemberCommonDialog(new MemberCommonDialog.SimpleListener() {
                    @Override
                    public void onPositive(Object... objects) {
                        // 跳转填写审批信息// 审批类型 1 申请加盟(固定传1就行) 2邀请加盟
                        jumpJoinPage(status);
                    }
                }, MemberCommonDialog.STYLE_INVITE_JOIN);
                dialog.show(getActivity(), "MemberCommonDialog");
            } else {
                jumpJoinPage(status);
            }
        });
    }


    private void jumpJoinPage(String status) {
        // 跳转邀请加盟申请页
        if (status.equals("1")) {//有审批
            ComApplyOrInvitePersonShenPiActivity.start(requireActivity(), bean1, false, 0);//0 表示邀请  企业  邀请  个人
        } else {//无审批
            ComApplyOrInvitePersonActivity.start(requireActivity(), bean1, false, 0); //    企业  邀请  个人
        }
        //                MemberInviteJoinActivity.start(getActivity(), bean1);//企业 邀请 企业
    }


    private void initData() {
        //设置城市
        if (PermissionUtils.checkPermission(_mActivity, Manifest.permission.ACCESS_FINE_LOCATION)) {
            //设置经纬度
            double lat = NumberUtil.convertToDouble(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LATITUDE_ID, "0"));
            double log = NumberUtil.convertToDouble(SharedPreferenceUtil.getInstance().getString(SharedPreferenceUtil.LONGITUDE_ID, "0"));
            if (lat != 0 && log != 0) {
                //设置定位信息
                viewModel.ldFilter.getValue().setLatitude(lat);
                viewModel.ldFilter.getValue().setLongitude(log);
            }
        }
        mFilterAdapter.setTabTitle(TAB_CAR_LOCATION, "全国");
        //获取数据
        viewModel.getAddressModel(_mActivity);
        viewModel.getCarFunction();
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        if (viewModel.ldCarType.getValue() != null && tab.getPosition() < viewModel.ldCarType.getValue().size()) {
            mTypePop.setDefItem(tab.getPosition());
            //请求数据
            viewModel.ldFilter.getValue().setCarType(viewModel.ldCarType.getValue().get(tab.getPosition()));
            //根据车型筛选数据
            filterByCarType();
        }
    }

    /**
     * 根据车型筛选数据
     */
    private void filterByCarType() {
        //切换车型时重置车长，填充车长筛选数据
        viewModel.ldFilter.getValue().setCarLen(null);
        //刷新车长数据
        if (viewModel.ldFilter.getValue() != null && viewModel.ldFilter.getValue().getCarType() != null) {
            viewModel.ldCarLen.postValue(viewModel.ldFilter.getValue().getCarType().getCarLenList());
        }
        mFilterAdapter.setTabStatusAndTitle(TAB_CAR_LENGTH, LogisticsFilterTabAdapter.NORMAL, "车长");
        refreshList();
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {
        //不用实现
    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {
        //不用实现
    }

    /**
     * 首页刷新
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void homeRefresh(LogisticsEvent event) {
        if (event != null && event.getMessageTag() == EventConstant.EVENT_LOGISTICS_REFRESH) {
            /*  viewModel.getAddressModel(_mActivity);*/
            refreshList();
        }
    }

    private void refreshList() {
        mPage = 1;
        if (viewModel.ldCarType.getValue() == null) {
            //获取数据
            viewModel.getAddressModel(_mActivity);
            viewModel.getCarFunction();
        } else {
            viewModel.getCarToList(getActivity(), mPage);
            binding.ivFindCarByMapBackTop.setVisibility(View.GONE);
        }
    }

    //列表
    public void syncData(ProListEntity<List<CarHallEntity>> entity) {
        binding.srlFindCarByMap.finishRefresh();
        binding.srlFindCarByMap.finishLoadMore();
        if (entity == null)
            return;
        if (entity.getPageNumber() == 1) {
            mList.clear();
        }
        if (entity.getList() != null) {
            mList.addAll(entity.getList());
        }
        mAdapter.notifyDataSetChanged();
        //判断列表是否为null
        if (mList.size() == 0) {
            binding.srlFindCarByMap.setVisibility(View.GONE);
            binding.emptyView.setVisibility(View.VISIBLE);
        } else {
            binding.srlFindCarByMap.setVisibility(View.VISIBLE);
            binding.emptyView.setVisibility(View.GONE);
        }
        //
        if (entity.getPageNumber() < entity.getTotalPage()) {
            mPage = entity.getPageNumber() + 1;
            binding.srlFindCarByMap.resetNoMoreData();
        } else {
            binding.srlFindCarByMap.finishLoadMoreWithNoMoreData();
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_find_car_by_map_edit:
                if (viewModel.ldCarType.getValue() != null) {
                    binding.ivFindCarByMapEdit.setImageResource(R.mipmap.icon_tab_pack_up);
                    EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
                    new Handler().postDelayed(() -> mTypePop.showPopwindow(binding.llFindCarByMapCategory, 0, 0), 400);
                }
                break;
            case R.id.iv_find_car_by_map_back_top:
                binding.carsList.smoothScrollToPosition(0);
                break;
        }
    }

    /**
     * 展示选择弹窗
     */
    public void showPopup(BasePopWindow pop) {
        if (getActivity() instanceof MainActivity) {
            EventBus.getDefault().post(LogisticsEvent.make().setMessageTag(EventConstant.EVENT_LOGISTICS_WINDOW_TOP));
            new Handler().postDelayed(() -> pop.showPopwindow(binding.rvFindCarByMapFilter, 0, 0), 300);
        } else {
            pop.showPopwindow(binding.rvFindCarByMapFilter, 0, 0);
        }
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}